<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.jframe.sso.model.CurUser" %>
<%@ page import="com.jframe.sys.webui.Accrodion" %>
<%@ page import="com.jframe.sys.utils.SpringUtil" %>
<%@ page import="com.jframe.cfg.service.SysmenuService" %>
<%
SysmenuService sysmenuService = (SysmenuService)SpringUtil.getBean("sysmenuService");
CurUser user = (CurUser)session.getAttribute("curUser");
List<Accrodion> accrodions = sysmenuService.findRoleAccrodions(user);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>后台管理</title>
<link rel="stylesheet" type="text/css" href="js/easyui/themes/<%=user.getSkin() %>/easyui.css">
<link rel="stylesheet" type="text/css" href="js/easyui/themes/icon.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/inc.js"></script>
<script type="text/javascript" src="js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui/easyui.extend.window.js"></script>
<script type="text/javascript" src="js/easyui/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
a:link {
 text-decoration: none;
}
a:visited {
 text-decoration: none;
}
a:hover {
 text-decoration: underline;
}
a:active {
 text-decoration: none;
}
.cs-north-bg {
	width: 100%;
	height: 100%;
	padding-top: 0px;
}
.north-logo {
	width:50%;
	float:left;	
}
.ui-skin-nav {
    float: right;
	padding: 0;
	margin-right: 10px;
	list-style: none outside none;
	height: 30px;
}
</style>  
<script type="text/javascript">
<!--
function addTab(title, url,iconCls){
	if(iconCls==''||iconCls==null){
		iconCls='icon_earth';
	}
	if ($('#tabs').tabs('exists', title)){
		$('#tabs').tabs('select', title);//选中并刷新
		var currTab = $('#tabs').tabs('getSelected');
		var url = $(currTab.panel('options').content).attr('src');
		if(url != undefined && currTab.panel('options').title != 'Home') {
			$('#tabs').tabs('update',{
				tab:currTab,
				options:{
					content:createFrame(url)
				}
			});
		}
	} else {
		url = '<%=request.getContextPath()%>/'+url;
		var content = createFrame(url);
		$('#tabs').tabs('add',{
			title:title,
			content:content,
			closable:true,
			iconCls:iconCls
		});
	}
	tabClose();
}

function createFrame(url) {
	var s = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
	return s;
}
		
function tabClose() {
	/*双击关闭TAB选项卡*/
	$(".tabs-inner").dblclick(function(){
		var subtitle = $(this).children(".tabs-closable").text();
		$('#tabs').tabs('close',subtitle);
	});
	/*为选项卡绑定右键*/
	$(".tabs-inner").bind('contextmenu',function(e){
		$('#mm').menu('show', {
			left: e.pageX,
			top: e.pageY
		});
		var subtitle =$(this).children(".tabs-closable").text();
		$('#mm').data("currtab",subtitle);
		$('#tabs').tabs('select',subtitle);
		return false;
	});
}		

//刷新tab
var refresh = function(){
	var currTab = $('#tabs').tabs('getSelected');
	var url = $(currTab.panel('options').content).attr('src');
	if(url != undefined && currTab.panel('options').title != '主页') {
		$('#tabs').tabs('update',{
			tab:currTab,
			options:{
				content:createFrame(url)
			}
		});
	}
};

var loginOut = function(){
	econfirm("提示","您确定要退出本次登录吗？",function(data){
		if(data){
			self.location="loginAction.action?method=loginOut";
		}
	},"消息");
};

function personInfo(){
	showWin('&nbsp;','userAction.do?method=goUserInfo',600,300);
}
//绑定右键菜单事件
function tabCloseEven() {
	//刷新
	$('#mm-refresh').click(refresh);
	
	//关闭当前
	$('#mm-close').click(function(){
		var currtab_title = $('#mm').data("currtab");
		$('#tabs').tabs('close',currtab_title);
	});
	
	//全部关闭
	$('#mm-closeall').click(function(){
		$('.tabs-inner span').each(function(i,n){
			var t = $(n).text();
			if(t != '主页') {
				$('#tabs').tabs('close',t);
			}
		});
	});
	
	//关闭除当前之外的TAB
	$('#mm-closeother').click(function(){
		var prevall = $('.tabs-selected').prevAll();
		var nextall = $('.tabs-selected').nextAll();		
		if(prevall.length>0){
			prevall.each(function(i,n){
				var t=$('a:eq(0) span',$(n)).text();
				if(t != '主页') {
					$('#tabs').tabs('close',t);
				}
			});
		}
		if(nextall.length>0) {
			nextall.each(function(i,n){
				var t=$('a:eq(0) span',$(n)).text();
				if(t != '主页') {
					$('#tabs').tabs('close',t);
				}
			});
		}
		return false;
	});
	
	//关闭当前右侧的TAB
	$('#mm-closeright').click(function(){
		var nextall = $('.tabs-selected').nextAll();
		if(nextall.length==0){
			return false;
		}
		nextall.each(function(i,n){
			var t=$('a:eq(0) span',$(n)).text();
			$('#tabs').tabs('close',t);
		});
		return false;
	});
	
	//关闭当前左侧的TAB
	$('#mm-closeleft').click(function(){
		var prevall = $('.tabs-selected').prevAll();
		if(prevall.length==0){
			return false;
		}
		prevall.each(function(i,n){
			var t=$('a:eq(0) span',$(n)).text();
			if(t != '主页') {
				$('#tabs').tabs('close',t);
			}
		});
		return false;
	});

	//退出
	$("#mm-exit").click(function(){
		$('#mm').menu('hide');
	});
}

$(function() {
	tabCloseEven();	
	$('.cs-navi-tab').click(function() {
		var $this = $(this);
		var href = $this.attr('src');
		var title = $this.text();
		addTab(title, href,'');
	});
	
	var loadTree = function(title){
		  $("ul[name='"+title+"']").tree({
				url:'loginAction.do?method=getTrees&title='+encodeURIComponent(title),
				onBeforeExpand:function(node,param){
					$("ul[name='"+title+"']").tree('options').url = "loginAction.do?method=getTrees&id="+node.id;                       
				},
				onClick:function(node){     
					if($("ul[name='"+title+"']").tree('isLeaf', node.target)){
						$.ajax({
					 		url:'loginAction.action?method=getUrl',
					 		type: 'post',
						    data:{
						    	id:node.id
						    },
						    dataType: 'json',
						    error: function(){
						        alertError('登陆超时，请重新登陆！');
						        self.location="loginAction.action?method=loginOut";
						    },
						    success: function(data){
						    	if(data.url!=null&&data.url!=""){
						    		addTab(data.title,data.url,data.iconCls);
						    	}else{
						    		alertInfo("该菜单还未配置链接");
						    	}
						    }
					 	});
					}				 	
				}
		});
	};
	
	$('#accordion-root').accordion({
		onSelect:loadTree
	});	
	<%
	//初始化第一个accrodions tree
	if(accrodions.size()>0){
	%>
	loadTree('<%=accrodions.get(0).getTitle()%>');
	<%
	}
	%>
});
-->
</script>
</head>
<body class="easyui-layout">
	<div region="north" border="false" style="height:70px;" class="panel-backgroundcolor" >
		<div class="north-logo">
		<!-- 	<img src="images/jframe2.png" alt="logo" style="height:65px">&nbsp; -->
		</div>
		<div style="float:right;padding-top: 8px;width:20%" align="right">
			<a href="javascript:personInfo()" title="个人信息"><img src="images/person_info.png" alt="logo" style="height:55px;width:55px;border: 0px;"></a>&nbsp;&nbsp;
			<a href="#" title="返回主页"><img src="images/icon_index.png" alt="logo" style="height:55px;width:55px;border: 0px;"></a>&nbsp;&nbsp;
			<a href="javascript:loginOut()" title="退出"><img src="images/closed.png" alt="logo" style="height:55px;width:55px;border: 0px;"></a>&nbsp;
		</div>
	</div>
	<div region="west" border="true" split="true" title="系统菜单" class="cs-west" style="width:200px;" iconCls="icon-home">
		<div class="easyui-accordion" fit="true" border="false" id="accordion-root">
			<%
			for(Accrodion accrodion:accrodions){
			%>
			<div title="<%=accrodion.getTitle()%>" iconCls="<%=accrodion.getIconCls()%>">
				<ul class='tree' name='<%=accrodion.getTitle()%>'> 
				
				</ul>
			</div>
			<% 
			}
			%>
		</div>
	</div>
	<div id="mainPanle" region="center" border="true" border="false">
		 <div id="tabs" class="easyui-tabs"  fit="true" border="false" >
            <div title="主页" iconCls="icon_home">
				<iframe scrolling="auto" frameborder="0"  src="jframe/welcome.jsp" style="width:100%;height:98%;"></iframe>
			</div>
        </div>
	</div>
	<div region="south" border="false" id="south" class="panel-backgroundcolor"><center>技术支持：l2iu工作室&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;邮箱:l2iu11@126.com</center></div>	
	<div id="mm" class="easyui-menu cs-tab-menu" style="width: 150px;">
		<div id="mm-refresh">刷新</div> 
		<div class="menu-sep"></div>
		<div id="mm-close">关闭</div>
		<div id="mm-closeall">全部关闭</div>
		<div id="mm-closeother">除此之外全部关闭</div>
		<div class="menu-sep"></div>
		<div id="mm-closeright">当前页右侧全部关闭</div>
		<div id="mm-closeleft">当前页左侧全部关闭</div>
	</div>
</body>
</html>
